﻿<cfsilent>
	<cfscript>
		
		termId = event.getArg("TermID", event.getArg("TID"));
		studentId = event.getArg("STU");

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");

		rs_choosen = queryNew("cid");
		
		if ( len(studentId) and len(termId) ) {
			
			/* 读取学生的已选课程 */
			sql = "	SELECT
						c.cid,c.course_name,c.course_credit,
						ct.turn,
						sc.task_type,sc.scc_id,sc.st,sc.retaking,
						sc.choose_time,sc.choose_prop,sc.task_id,cp.prop_name
					FROM
						t_student_course sc
						INNER JOIN t_course c ON sc.cid = c.cid
						INNER JOIN t_choose_turn ct ON ct.ct = sc.ct
						INNER JOIN t_course_prop cp ON sc.prop_id = cp.prop_id
					WHERE
						sc.stu_id = :studentId 
						AND
						sc.term_id = :termId 
					ORDER BY
						sc.task_type DESC";
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
			queryObj.addParam(name = "studentId", value = studentId, cfsqltype = "cf_sql_varchar");
			rs_choosen = queryObj.execute(sql = sql).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount>
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>教学班</td>
				<td nowrap="nowrap">任课教师</td>
				<td nowrap="nowrap">学分</td>
				<td>开课类别</td>
				<td>修读方式</td>
				<td>性质</td>
				<td nowrap="nowrap">重修</td>
				<td>上课时间</td>
				<td>上课地点</td>
				<td>选课时间</td>
				<td></td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
            <cfloop query="rs_choosen">
				<cfset row++ />
			
				<!--- 读取教学任务教师和任务性质 --->
				<cfswitch expression="#rs_choosen.task_type#">
					<cfcase value="P">
						<cfset sql = "	SELECT
											tch.tch_name,c.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_task tsk
											INNER JOIN t_teacher tch ON tsk.tch_id = tch.tch_id
											INNER JOIN t_campus c ON c.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name = "taskId", value = rs_choosen.task_id, cfsqltype = "cf_sql_varchar")/>
                        <cfset rs_taskEntity = queryObj.execute(sql = sql).getResult() />
					</cfcase>
					<cfcase value="C">
						<cfset sql = "	SELECT
											tch.tch_name,c.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_common_task tsk
											INNER JOIN t_teacher tch ON tsk.tch_id = tch.tch_id
											INNER JOIN t_campus c ON c.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name = "taskId", value = rs_choosen.task_id, cfsqltype = "cf_sql_varchar")/>
                        <cfset rs_taskEntity = queryObj.execute(sql = sql).getResult() />
					</cfcase>
					<cfcase value="R">
						<cfset sql = "	SELECT
											tch.tch_name,c.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_reopen_task tsk
											INNER JOIN t_teacher tch ON tsk.tch_id = tch.tch_id
											INNER JOIN t_campus c ON c.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name = "taskId", value = rs_choosen.task_id, cfsqltype = "cf_sql_varchar")/>
                        <cfset rs_taskEntity = queryObj.execute(sql = sql).getResult() />
					</cfcase>
					<cfcase value="T">
						<cfset sql = "	SELECT
											tch.tch_name,c.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_sport_task tsk
											INNER JOIN t_teacher tch ON tsk.tch_id = tch.tch_id
											INNER JOIN t_campus c ON c.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name = "taskId", value = rs_choosen.task_id, cfsqltype = "cf_sql_varchar")/>
                        <cfset rs_taskEntity = queryObj.execute(sql = sql).getResult() />
					</cfcase>
				</cfswitch>
				<cfif rs_taskEntity.recordCount>
					<!--- 如果教学任务有效 --->
					<cfset taskProp.parseProperty( rs_taskEntity.task_prop ) />
					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput></td>
						<td><cfoutput>#rs_taskEntity.tch_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
						<td nowrap="nowrap"><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>
						<td nowrap="nowrap"><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td nowrap="nowrap"><cfoutput>#rs_choosen.prop_name#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是<cfelse>否</cfif></td>
						<td nowrap="nowrap"><cfoutput>#replace(mathAdvice.convertTaskTime(rs_taskEntity.task_time), ",", "<br/>", "all")#</cfoutput></td>
						<td nowrap="nowrap"><cfoutput>#replace(rs_taskEntity.task_place, ",", "<br/>", "all")#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.choose_time, 'YYYY/MM/DD')#</cfoutput></span></td>
						<td>
							<cfif taskProp.getDischarge()>
									<span title="该教学班禁止退课" class="stat locked"></span>
								<cfelse>
									<a title="撤销课程" class="stat delete" href="javascript:removeTask('<cfoutput>#rs_choosen.scc_id#</cfoutput>','<cfoutput>#rs_choosen.cid#</cfoutput>','<cfoutput>#studentId#</cfoutput>','<cfoutput>#termId#</cfoutput>','<cfoutput>#rs_choosen.task_type#</cfoutput>','<cfoutput>#rs_choosen.task_id#</cfoutput>');"></a>
							</cfif>
						</td>
					</tr>
					<!--- javascript:removeTask(chooserId, courseId, stuId, termId, taskType, taskId); --->
					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>
			</cfloop>
		</tbody>
	</table>
	<cfelse>
	<div class="systemNotice">
		<h3>学生没有选课</h3>
	</div>
</cfif>